package com.atguigu.eduservice.controller.front;

import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.CourseService;
import com.atguigu.eduservice.service.TeacherService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @create: 2022/10/9
 * @Description:
 * @FileName: TeacherFrontController
 * @自定义内容：
 */
@RestController
@RequestMapping("/eduservice/teacherFront")
public class TeacherFrontController {

    @Autowired
    private TeacherService teacherService;

    @Autowired
    private CourseService courseService;

    //1 分页查询讲师方法
    @PostMapping("getTeacherFrontList/{currentPage}/{limit}")
    public R getTeacherFrontList(@PathVariable Long currentPage, @PathVariable Long limit){

        Page<EduTeacher> teacherPage = new Page<>(currentPage,limit);
        Map<String,Object> map = teacherService.getTeacherFrontList(teacherPage);

        //返回所有数据
        return R.ok().data(map);
    }

    //2 讲师详细的方法
    @GetMapping("getTeacherFrontInfo/{teacherId}")
    public R getTeacherFrontInfo(@PathVariable String teacherId){
        //1、根据讲师id查询讲师基本信息
        EduTeacher eduTeacher = teacherService.getById(teacherId);

        //2、根据讲师id查询所讲课程
        LambdaQueryWrapper<EduCourse> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EduCourse::getTeacherId,teacherId);
        List<EduCourse> courseList = courseService.list(wrapper);

        return R.ok().data("teacher",eduTeacher).data("courseList",courseList);
    }
}
